package com.yuneec.droneservice.command;

import com.MAVLink.yuneec.msg_mav_rc_cmd_ack;
import com.yuneec.droneservice.request.IResponse;

import java.nio.charset.Charset;

/**
 * Created by gjw on 2017/3/27.
 */

public class GetControllerType extends BaseCommand {

    public GetControllerType() {
        super(MAV_RC_COMMAND.MAV_RC_CMD_GET_CONTROL_TYPE);
    }

    @Override
    protected short[] body() {
        return null;
    }

    @Override
    public IResponse<String> toResponse(msg_mav_rc_cmd_ack ack) {
        int code = ack.code;
        IResponse<String> response = new IResponse(ids(), code);
        if (code == MAV_RC_ERROR_CODE.MAV_RC_ERR_SUCCESS) {
            try {
                int len = uIntArrayToUShort(ack.params, 0);
                response.setParam(new String(uIntArrayToByteArray(ack.params, 1, len), Charset.forName("utf8")));
            } catch (Exception e) {
                response.setParam("N/A");
            }
        }
        return response;
    }

}
